﻿using System.Collections.Generic;
using HK.Core.Network.Download.Data;
using HK.Core.Network.Download.Protocol.Data;
using HK.Core.Threader.Protocol;

namespace HK.Core.Network.Download.Protocol.Control
{

    /// <summary>
    /// 事件委托定义 : 下载进度回调
    /// <param name="iDownloadedCount">已下载完成文件数</param>
    /// <param name="iTotalCount">下载文件总数</param>
    /// <param name="iDownloadedSize">已下载文件大小(单位:Byte)</param>
    /// <param name="iTotalSize">下载文件总大小(单位:Byte)</param>
    /// <param name="iCostTime">耗时(单位:毫秒)</param>
    /// <param name="iCurrent">当前完成下载文件信息</param>
    /// </summary>
    public delegate void DownloadProgress(int iDownloadedCount, int iTotalCount, 
        long iDownloadedSize, long iTotalSize, long iCostTime, IDownloadInfo iCurrent = null);

    /// <summary>
    /// 事件委托定义 : 下载失败回调
    /// <param name="iState">下载状态</param>
    /// <param name="iMessage">Message</param>
    /// <param name="iTarget">下载失败目标信息</param>
    /// </summary>
    public delegate void DownloadFailed(DownloadState iState, string iMessage = null, IDownloadInfo iTarget = null);
    
    /// <summary>
    /// 接口 : 下载管理器
    /// </summary>
    public interface IDownloadManager : IThreader
    {

#region Event

        /// <summary>
        /// 事件：下载进度
        /// </summary>
        DownloadProgress Progress { get; }
        
        /// <summary>
        /// 事件：下载失败
        /// </summary>
        DownloadFailed Failed { get; }
        
#endregion

#region Params

        /// <summary>
        /// 状态
        /// </summary>
        DownloadState State { get; }
        
        /// <summary>
        /// 状态描述
        /// </summary>
        string StateDes { get; }

        /// <summary>
        /// 线程上限数
        /// <para>* 后台同时开启多少个下载线程</para>
        /// </summary>
        int ThreaderMaxNun { get; }
        
        /// <summary>
        /// 运行中的子线程数
        /// </summary>
        int RunningChildThreaderCount { get; }
        
        /// <summary>
        /// 已经完成的下载个数
        /// </summary>
        int DownloadedCount { get; }
        
        /// <summary>
        /// 下载总数
        /// </summary>
        int TotalCount { get; }
        
        /// <summary>
        /// 完成下载大小
        /// <para>* 单位 : Byte</para>
        /// </summary>
        long DownloadedSize { get; }
        
        /// <summary>
        /// 下载总大小
        /// <para>* 单位 : Byte</para>
        /// </summary>
        long TotalSize { get; }
        
        /// <summary>
        /// 下载速度
        /// </summary>
        DownloadSpeed Speed { get; }
        
#endregion

#region Downloader

        /// <summary>
        /// 下载器列表
        /// </summary>
        IDownloader[] Downloaders { get; }

        /// <summary>
        /// 空闲下载器数量
        /// </summary>
        int IdleDownloaderCount { get; }
        
#endregion

        /// <summary>
        /// 开始下载
        /// </summary>
        /// <param name="iTargets">下载目标列表</param>
        /// <param name="iProgress">下载进度回调</param>
        /// <param name="iFailed">下载失败回调</param>
        void StartDownload(IList<IDownloadInfo> iTargets, DownloadProgress iProgress = null, DownloadFailed iFailed = null);

    }
}
